<?php
/*
 * @Description    : 检测接口
 * @Version        : 1.0.0
 * @Author         : QianLong
 * @Date           : 2021-04-05 17:13:54
 * @LastEditors    : QianLong
 * @LastEditTime   : 2024-04-10 10:10:43
 */

namespace app\notify\controller;

use app\common\model\Manager;
use app\common\RedisCache;

class Check extends \app\BaseController
{
    protected $redisCache;
    protected $platformSetting;
    protected $infoData;
    public function initialize()
    {
        $this->redisCache = new RedisCache();
    }
    public function userExpireCheck()
    {
        $time = time();
        $ntime = $time + 259199;
        $userList = Manager::field('id,phone,version,version_end_time,send_status')->where('version_end_time', '<', $ntime)->where('version', '>', 1)->select()->toArray();
        $http = new \Yurun\Util\HttpRequest;
        foreach ($userList as $key => $vo) {
            $time_cha = $vo['version_end_time'] - $time;
            if ($time_cha < 674800 && $time_cha > 259200) {
                if ($vo['send_status'] != 1) {
                    Manager::where('id', $vo['id'])->update(['send_status' => 1]);
                    $smsPostData['params_json'] = json_encode(['time' => date('Y-m-d H:i', $vo['version_end_time'])]);
                    $smsPostData['st_id'] = 'ST-4840767311749775';
                    $smsPostData['phone'] = $vo['phone'];
                    doSendSms($smsPostData);
                }
            } elseif ($time_cha < 259200 && $time_cha > 86400) {
                if ($vo['send_status'] != 2) {
                    Manager::where('id', $vo['id'])->update(['send_status' => 2]);
                    $smsPostData['params_json'] = json_encode(['time' => date('Y-m-d H:i', $vo['version_end_time'])]);
                    $smsPostData['st_id'] = 'ST-4840767311749775';
                    $smsPostData['phone'] = $vo['phone'];
                    doSendSms($smsPostData);
                }
            } elseif ($time_cha < 86400 && $time_cha > 0) {
                if ($vo['send_status'] != 3) {
                    Manager::where('id', $vo['id'])->update(['send_status' => 3]);
                    $smsPostData['params_json'] = json_encode(['time' => date('Y-m-d H:i', $vo['version_end_time'])]);
                    $smsPostData['st_id'] = 'ST-4840767311749775';
                    $smsPostData['phone'] = $vo['phone'];
                    doSendSms($smsPostData);
                }
            }
        }
    }
    public function userExpire()
    {
        $time = time();
        $userList = Manager::field('id,phone,version,username')->where('version_end_time', '<', $time)->where('version','>',1)->select()->toArray();
        foreach ($userList as $key => $vo) {
            Manager::where('id', $vo['id'])->update(['version' => 1, 'version_end_time'=>0]);
            $smsPostData['params_json'] = json_encode(['name' => $vo['username']]);
            $smsPostData['st_id'] = 'ST-4840767184478284';
            $smsPostData['phone'] = $vo['phone'];
            doSendSms($smsPostData);
        }
    }
}
